package com.lcxw.hxzbapi.controller.homepagecontroller;

import com.alibaba.fastjson.JSONObject;
import com.lcxw.hxzbapi.controller.roomcontroller.RoomRealization;
import com.lcxw.hxzbapi.entity.response.Response;
import com.lcxw.hxzbapi.feign.adminFeignService.AdminService;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/homepage")
public class HomePageController {

    @Resource
    AdminService adminService;

    @Resource
    RoomRealization roomRealization;

    /**
     * 首页轮播图获取接口
     */
    @PostMapping("/carousel/getAll")
    public Response getAllCarousel(){
        return adminService.getAllCarousel();
    }

    /*
     *当前在播的房间推荐接口，一次最多获取6个
     */
    @PostMapping("/room/recommend")
    public Response getRoomRecommend(@RequestBody JSONObject requestBody){
        String roomType = requestBody.getString("roomType");
        List roomRecommend = roomRealization.getRoomPark(roomType);
        if (roomRecommend.size() >= 6){
            roomRecommend = roomRecommend.subList(0,5);
        }
        return Response.ok(roomRecommend);
    }

}
